package com.hq.common.domain;

/**

 * @since 2015-01-26 23:21
 */
public enum ResultCode {
    OK(200, "成功"),
    CREATED(201, "已创建"),
    ACCEPTED(202, "接受"),
    NO_CONTENT(204, "无内容"),
    NOT_MODIFIED(304, "没有改变"),
    BAD_REQUEST(400, "坏请求"),
    UNAUTHORIZED(401, "未授权的"),
    FORBIDDEN(403, "禁用"),
    NOT_FOUND(404, "没有找到"),
    METHOD_NOT_ALLOWED(405, "方法不被允许"),
    NOT_ACCEPTABLE(406, "不可接受的"),
    REQUEST_TIMEOUT(408, "请求超时"),
    CONFILICT(409, "冲突"),
    LENGTH_REQUIRED(411, "长度必须"),
    PRECONDITION_FAILED(412, "先决条件失败"),
    REQUEST_ENTITY_TOO_LARGE(413, "请求实体太大"),
    REQUEST_URI_TOO_LONG(414, "请求URI太长"),
    UNSUPPORTED_MEDIA_TYPE(415, "不被支持的媒体类型"),
    REQUESTED_RANGE_NOT_SATISFIABLE(416, "请求范围不满足"),
    EXPECTATION_FAILED(417, "期望失败"),
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    NOT_IMPLEMENTED(501, "没有实现"),
    SERVICE_UNAVAILABLE(503, "服务无效");

    private ResultCode(int code) {
        this.code = code;
    }

    private ResultCode(int code, String description) {
        this.code = code;
        this.description = description;
    }

    private int code;
    private String description;

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    public static ResultCode getResultCode(int code) {
        for (ResultCode resultCode : ResultCode.values()) {
            if (resultCode.getCode() == code) {
                return resultCode;
            }
        }
        return null;
    }
}
